//package com.smile.handler;
//
//
//import com.smile.mqtt.handler.AbstractStorageConfigGetHandler;
//
//import lombok.extern.slf4j.Slf4j;
//import org.eclipse.paho.client.mqttv3.MqttClient;
//import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
//import org.eclipse.paho.client.mqttv3.MqttException;
//import org.eclipse.paho.client.mqttv3.MqttMessage;
//import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
//import org.springframework.stereotype.Component;
//
//@Component
//@Slf4j
//public class DefaultStorageConfigGetHandler extends AbstractStorageConfigGetHandler {
//
//    public static void main(String[] args) {
////        StorageConfigGetData storageConfigGetData = new StorageConfigGetData();
////        StorageConfigGetData.StorageCredentials storageCredentials = new StorageConfigGetData.StorageCredentials();
////        // STS服务接入点，例如sts.cn-hangzhou.aliyuncs.com。您可以通过公网或者VPC接入STS服务。
////        String endpoint = "sts.cn-beijing.aliyuncs.com";
////        // 从环境变量中获取步骤1生成的RAM用户的访问密钥（AccessKey ID和AccessKey Secret）。
////        String accessKeyId = "LTAI5tKvX14c49JeHJNWyrUu";
////        String accessKeySecret = "zBiAWmclLqJb8ozr86otTYwRrtotba";
////        // 从环境变量中获取步骤3生成的RAM角色的RamRoleArn。
////        String roleArn = "acs:ram::1190819097046853:role/ramosstest";
////        // 自定义角色会话名称，用来区分不同的令牌，例如可填写为SessionTest。
////        String roleSessionName = "300737648089401286";
////        // 临时访问凭证将获得角色拥有的所有权限。
////        String policy = null;
////        // 临时访问凭证的有效时间，单位为秒。最小值为900，最大值以当前角色设定的最大会话时间为准。当前角色最大会话时间取值范围为3600秒~43200秒，默认值为3600秒。
////        // 在上传大文件或者其他较耗时的使用场景中，建议合理设置临时访问凭证的有效时间，确保在完成目标任务前无需反复调用STS服务以获取临时访问凭证。
////        Long durationSeconds = 3600L;
////        try {
////            // 发起STS请求所在的地域。建议保留默认值，默认值为空字符串（""）。
////            String regionId = "";
////            // 添加endpoint。适用于Java SDK 3.12.0及以上版本。
////            DefaultProfile.addEndpoint(regionId, "Sts", endpoint);
////            // 添加endpoint。适用于Java SDK 3.12.0以下版本。
////            // DefaultProfile.addEndpoint("",regionId, "Sts", endpoint);
////            // 构造default profile。
////            IClientProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret);
////            // 构造client。
////            DefaultAcsClient client = new DefaultAcsClient(profile);
////            final AssumeRoleRequest request = new AssumeRoleRequest();
////            // 适用于Java SDK 3.12.0及以上版本。
////            request.setSysMethod(MethodType.POST);
////            // 适用于Java SDK 3.12.0以下版本。
////            // request.setMethod(MethodType.POST);
////            request.setRoleArn(roleArn);
////            request.setRoleSessionName(roleSessionName);
////            request.setPolicy(policy);
////            request.setDurationSeconds(durationSeconds);
////            final AssumeRoleResponse response = client.getAcsResponse(request);
////
//////            if (log.isDebugEnabled()) {
////            System.out.println("读取配置");
////            System.out.println(response.getCredentials());
////            log.info("Expiration: " + response.getCredentials().getExpiration());
////            log.info("Access Key Id: " + response.getCredentials().getAccessKeyId());
////            log.info("Access Key Secret: " + response.getCredentials().getAccessKeySecret());
////            log.info("Security Token: " + response.getCredentials().getSecurityToken());
////            log.info("RequestId: " + response.getRequestId());
////            System.out.println("读取结束");
////
////
////
//////            GetStsTokenResponse getStsTokenResponse = new GetStsTokenResponse();
//////            getStsTokenResponse.setSecurityToken(response.getCredentials().getSecurityToken());
//////            getStsTokenResponse.setAccessKeyId(response.getCredentials().getAccessKeyId());
//////            getStsTokenResponse.setAccessKeySecret(response.getCredentials().getAccessKeySecret());
////
////
//////            return Boolean.TRUE;
////        } catch (ClientException | com.aliyuncs.exceptions.ClientException e) {
////            log.error("Failed：", e);
//////            return Boolean.FALSE;
////        }
//    }
//
//    @Override
//    public Boolean process(String data, String tid, String bid) throws MqttException {
//////        StorageConfigGetData storageConfigGetData = new StorageConfigGetData();
//////        StorageConfigGetData.StorageCredentials storageCredentials = new StorageConfigGetData.StorageCredentials();
////        // STS服务接入点，例如sts.cn-hangzhou.aliyuncs.com。您可以通过公网或者VPC接入STS服务。
////        String endpoint = "sts.cn-beijing.aliyuncs.com";
////        // 从环境变量中获取步骤1生成的RAM用户的访问密钥（AccessKey ID和AccessKey Secret）。
////        String accessKeyId = "LTAI5tKvX14c49JeHJNWyrUu";
////        String accessKeySecret = "zBiAWmclLqJb8ozr86otTYwRrtotba";
////        // 从环境变量中获取步骤3生成的RAM角色的RamRoleArn。
////        String roleArn = "acs:ram::1190819097046853:role/ramosstest";
////        // 自定义角色会话名称，用来区分不同的令牌，例如可填写为SessionTest。
////        String roleSessionName = "300737648089401286";
////        // 临时访问凭证将获得角色拥有的所有权限。
////        String policy = null;
////        // 临时访问凭证的有效时间，单位为秒。最小值为900，最大值以当前角色设定的最大会话时间为准。当前角色最大会话时间取值范围为3600秒~43200秒，默认值为3600秒。
////        // 在上传大文件或者其他较耗时的使用场景中，建议合理设置临时访问凭证的有效时间，确保在完成目标任务前无需反复调用STS服务以获取临时访问凭证。
////        Long durationSeconds = 3600L;
////        try {
////            // 发起STS请求所在的地域。建议保留默认值，默认值为空字符串（""）。
////            String regionId = "";
////            // 添加endpoint。适用于Java SDK 3.12.0及以上版本。
////            DefaultProfile.addEndpoint(regionId, "Sts", endpoint);
////            // 添加endpoint。适用于Java SDK 3.12.0以下版本。
////            // DefaultProfile.addEndpoint("",regionId, "Sts", endpoint);
////            // 构造default profile。
////            IClientProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret);
////            // 构造client。
////            DefaultAcsClient client = new DefaultAcsClient(profile);
////            final AssumeRoleRequest request = new AssumeRoleRequest();
////            // 适用于Java SDK 3.12.0及以上版本。
////            request.setSysMethod(MethodType.POST);
////            // 适用于Java SDK 3.12.0以下版本。
////            // request.setMethod(MethodType.POST);
////            request.setRoleArn(roleArn);
////            request.setRoleSessionName(roleSessionName);
////            request.setPolicy(policy);
////            request.setDurationSeconds(durationSeconds);
////            final AssumeRoleResponse response = client.getAcsResponse(request);
////
//////            if (log.isDebugEnabled()) {
////            System.out.println("读取配置");
////            log.info("Expiration: " + response.getCredentials().getExpiration());
////            log.info("Access Key Id: " + response.getCredentials().getAccessKeyId());
////            log.info("Access Key Secret: " + response.getCredentials().getAccessKeySecret());
////            log.info("Security Token: " + response.getCredentials().getSecurityToken());
////            log.info("RequestId: " + response.getRequestId());
//////            }
////            System.out.println("读取结束");
////
////            StorageConfigGetData.StorageCredentials storageCredentials = new StorageConfigGetData.StorageCredentials();
////            storageCredentials.setAccessKeyId(accessKeyId);
////            storageCredentials.setAccessKeySecret(accessKeySecret);
////            storageCredentials.setSecurityToken(response.getCredentials().getSecurityToken());
////            storageCredentials.setExpire(durationSeconds);
////
////            StorageConfigGetData.StorageOutput storageOutput = new StorageConfigGetData.StorageOutput();
////            storageOutput.setBucket("nhbtestbucket");
////            storageOutput.setCredentials(storageCredentials);
////            storageOutput.setEndpoint("https://oss-cn-hangzhou.aliyuncs.com");
////            storageOutput.setRegion("cn-hangzhou");
////            storageOutput.setProvider("{\"ali\":\"阿里云\"}");
////            storageOutput.setObjectKeyPrefix("nhb");
////
////            StorageConfigGetData storageConfigGetData = new StorageConfigGetData();
////            storageConfigGetData.setOutput(storageOutput);
////            storageConfigGetData.setResult(0);
////            DeviceConfigResponse<StorageConfigGetData> deviceConfigResponse = new DeviceConfigResponse<>();
////
////
////            deviceConfigResponse.setBid(bid);
////            deviceConfigResponse.setTid(tid);
////            deviceConfigResponse.setData(storageConfigGetData);
////
////            deviceConfigResponse.setTimestamp(System.currentTimeMillis());
////            deviceConfigResponse.setMethod("storage_config_get");
////            deviceConfigResponse.setGateway("8UUXN2800A00HX");
////            System.out.println("DefaultConfigGetHandler发送的结果为:" + com.alibaba.fastjson.JSONObject.toJSONString(deviceConfigResponse));
////
////
////            MqttMessage message = new MqttMessage();
////            message.setQos(0);
////            message.setRetained(true);
////            message.setPayload(com.alibaba.fastjson2.JSONObject.toJSONString(deviceConfigResponse).getBytes());
////            MqttClient mqttClient = new MqttClient("tcp://120.211.119.131:1883", "feisuan-mqtt-producer-client", new MemoryPersistence());
////            MqttConnectOptions connOpts = new MqttConnectOptions();
////            connOpts.setUserName("feisuan");
////            connOpts.setPassword("feisuan123456".toCharArray());
////            mqttClient.connect(connOpts);
////
////            mqttClient.publish("thing/product/" + "8UUXN2800A00HX" + "/requests_reply", message);
////
////
////
//////            GetStsTokenResponse getStsTokenResponse = new GetStsTokenResponse();
//////            getStsTokenResponse.setSecurityToken(response.getCredentials().getSecurityToken());
//////            getStsTokenResponse.setAccessKeyId(response.getCredentials().getAccessKeyId());
//////            getStsTokenResponse.setAccessKeySecret(response.getCredentials().getAccessKeySecret());
//
//
//            return Boolean.TRUE;
////        } catch (ClientException | com.aliyuncs.exceptions.ClientException e) {
////            log.error("Failed：", e);
////            return Boolean.FALSE;
////        }
//
//    }
//}
